package com.lawyer.drive.server;


import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;

import java.io.IOException;

import java.net.URISyntaxException;
import java.security.GeneralSecurityException;


import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential;
import com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer;
import com.google.api.client.googleapis.services.GoogleClientRequestInitializer;



public class DriveServerUtil {
	  private static String CLIENT_ID = "936702696371-alq4eutiumusupouvns6mso43rq6dquv.apps.googleusercontent.com";
	  private static String CLIENT_SECRET = "lfmPDmAnK3N3jCJNzLYz4rpq";

	  private static String REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob";
	  /** The API Key of the project */
	  private static final String API_KEY = "AIzaSyCwGfUPnie3l0FNFtdnEyVFiH4_OdebVEM";

	  /**
	   * Build and returns a Drive service object authorized with the
	   * application's service accounts.
	   *
	   * @return Drive service object that is ready to make requests.
	   */
	  
	// more work
	  
	  public static void addAttach( final File attache) throws Exception {
			
			try {
				System.out.println("Try  Start");
				
				System.out.println("Try  End");
			} catch (final Exception e) {
				e.printStackTrace();
				throw new Exception(e.getMessage());
			} finally {
				
			}
		}
	  
	 
	 
	  public static Drive getDriveService() throws GeneralSecurityException,
	      IOException, URISyntaxException {
	    HttpTransport httpTransport = new NetHttpTransport();
	    JsonFactory jsonFactory = new JacksonFactory();
	    AppIdentityCredential credential =
	        new AppIdentityCredential.Builder(DriveScopes.DRIVE).build();
	    GoogleClientRequestInitializer keyInitializer =
	        new CommonGoogleClientRequestInitializer(API_KEY);
	    Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
	        .setHttpRequestInitializer(credential)
	        .setGoogleClientRequestInitializer(keyInitializer)
	        .build();
	    return service;
	  }	  
	  
	  
}
